<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Set socket I/O activity timeout</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="gearmanworker.setoptions.html">GearmanWorker::setOptions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="gearmanworker.timeout.html">GearmanWorker::timeout</a></div>
 <div class="up"><a href="class.gearmanworker.html">GearmanWorker</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="gearmanworker.settimeout" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">GearmanWorker::setTimeout</h1>
  <p class="verinfo">(PECL gearman &gt;= 0.6.0)</p><p class="refpurpose"><span class="refname">GearmanWorker::setTimeout</span> &mdash; <span class="dc-title">Set socket I/O activity timeout</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-gearmanworker.settimeout-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>GearmanWorker::setTimeout</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$timeout</code></span>
   )</div>

  <p class="para rdfs-comment">
   Sets the interval of time to wait for socket I/O activity.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-gearmanworker.settimeout-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">timeout</code></em></dt>

     <dd>

      <p class="para">
       An interval of time in milliseconds.  A negative value indicates an infinite timeout.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-gearmanworker.settimeout-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Always returns <strong><code>TRUE</code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-gearmanworker.settimeout-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4239">
    <p><strong>Example #1 A simple worker with a 5 second timeout</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Starting\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">#&nbsp;Create&nbsp;our&nbsp;worker&nbsp;object.<br /></span><span style="color: #0000BB">$gmworker</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">GearmanWorker</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">#&nbsp;Add&nbsp;default&nbsp;server&nbsp;(localhost).<br /></span><span style="color: #0000BB">$gmworker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">#&nbsp;Register&nbsp;function&nbsp;"reverse"&nbsp;with&nbsp;the&nbsp;server.<br /></span><span style="color: #0000BB">$gmworker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"reverse_fn"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">#&nbsp;Set&nbsp;the&nbsp;timeout&nbsp;to&nbsp;5&nbsp;seconds<br /></span><span style="color: #0000BB">$gmworker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTimeout</span><span style="color: #007700">(</span><span style="color: #0000BB">5000</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"Waiting&nbsp;for&nbsp;job...\n"</span><span style="color: #007700">;<br />while(@</span><span style="color: #0000BB">$gmworker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">work</span><span style="color: #007700">()&nbsp;||&nbsp;</span><span style="color: #0000BB">$gmworker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">returnCode</span><span style="color: #007700">()&nbsp;==&nbsp;</span><span style="color: #0000BB">GEARMAN_TIMEOUT</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$gmworker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">returnCode</span><span style="color: #007700">()&nbsp;==&nbsp;</span><span style="color: #0000BB">GEARMAN_TIMEOUT</span><span style="color: #007700">)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#&nbsp;Normally&nbsp;one&nbsp;would&nbsp;want&nbsp;to&nbsp;do&nbsp;something&nbsp;useful&nbsp;here&nbsp;...<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Timeout.&nbsp;Waiting&nbsp;for&nbsp;next&nbsp;job...\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;continue;<br />&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$gmworker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">returnCode</span><span style="color: #007700">()&nbsp;!=&nbsp;</span><span style="color: #0000BB">GEARMAN_SUCCESS</span><span style="color: #007700">)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"return_code:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$gmworker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">returnCode</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;}<br />}<br /><br />echo&nbsp;</span><span style="color: #DD0000">"Done\n"</span><span style="color: #007700">;<br /><br />function&nbsp;</span><span style="color: #0000BB">reverse_fn</span><span style="color: #007700">(</span><span style="color: #0000BB">$job</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">strrev</span><span style="color: #007700">(</span><span style="color: #0000BB">$job</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">workload</span><span style="color: #007700">());<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     Running the worker with no submitted jobs will generate output that looks like the following:
    </p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Starting
Waiting for job...
Timeout. Waiting for next job...
Timeout. Waiting for next job...
Timeout. Waiting for next job...
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-gearmanworker.settimeout-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="gearmanworker.timeout.html" class="methodname" rel="rdfs-seeAlso">GearmanWorker::timeout()</a> - Get socket I/O activity timeout</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="gearmanworker.setoptions.html">GearmanWorker::setOptions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="gearmanworker.timeout.html">GearmanWorker::timeout</a></div>
 <div class="up"><a href="class.gearmanworker.html">GearmanWorker</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
